package com.organization.model.dao.impl

import com.organization.util.CustomHibernateDaoSupport
import com.organization.model.dao.ProjectDao
import org.springframework.stereotype.Repository
import com.organization.model.Project
import com.organization.model.Department

/**
 * Created with IntelliJ IDEA.
 * User: inester
 * Date: 10.07.12
 * Time: 13:26
 * To change this template use File | Settings | File Templates.
 */
@Repository("projectDao")
class ProjectDaoImpl extends CustomHibernateDaoSupport implements ProjectDao {

    @Override
    public void save(Project proj){
        getHibernateTemplate().save(proj);
    }

    @Override
    public void update(Project proj){
        getHibernateTemplate().update(proj);
    }

    @Override
    public void delete(Project proj){
        getHibernateTemplate().delete(proj);
    }

    @Override
    List<Project> projectList() {
        getHibernateTemplate().find("from Project")
    }

    List<Project> findAllByDepartment(Department dep){
         getHibernateTemplate().findByNamedParam("from Project where department= :dep","dep",dep)
    }

    @Override
    Project get(int id) {
        List<Project> projs = getHibernateTemplate().findByNamedParam("from Project where id = :projId","projId",id)
        return projs[0]
    }

}
